﻿using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Xml;
using System.Xml.Serialization;

namespace Jn698._45Tool.Utils
{
    internal class XmlHelper
    {
        public static void Serializer<T>(string file,T t)
        {
            Stream stream = new FileStream(file, FileMode.Create);
            using (XmlWriter xmlWriter = new XmlTextWriter(stream,Encoding.Unicode))
            {
                new XmlSerializer(typeof(T)).Serialize(xmlWriter, t);
            }
        }

        public static T Deserializer<T>(string file)
        {
            var xml = File.ReadAllText(file);
            using (StringReader reader = new StringReader(xml))
            {
                var model = new XmlSerializer(typeof(T)).Deserialize(reader);
                return (T)model;
            }
        }
    }
}
